package com.ericsson.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ericsson.web.core.HSQLDatabase;
import com.ericsson.web.core.IDatabase;

public class DBOperator extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, 
			HttpServletResponse response) 
	throws ServletException, IOException {
		String cmd = request.getParameter("cmd");
		if(cmd !=  null) {
			if(cmd.equals("clearCookie")) {
				cleanCookie();
				response.sendRedirect("/xss-demo/hacker.jsp");
			}
		}
	}
	
	@Override
	protected void doPost(HttpServletRequest request, 
			HttpServletResponse response) 
	throws ServletException, IOException {
		doGet(request, response);
	}
	
	private void cleanCookie() {
		IDatabase db = HSQLDatabase.getInstance();
		db.cleanCookie();
	}
}
